package controllers

import (
	"fmt"
	// "strconv"
)

type CheckController struct {
	MainController
}

func (this *CheckController) Post() {
	idPer := this.GetString("id")
	userFile1 := ".\\models\\data\\1.json"
	userFile2 := ".\\models\\data\\2.json"
	userFile3 := ".\\models\\data\\3.json"
	firstPer, err := ReadFile(userFile1)
	if err != nil {
		fmt.Println("readFile: ", err.Error())
		return
	}
	// num1 := strconv.Itoa(len(firstPer))
	secondPer, err2 := ReadFile(userFile2)
	if err2 != nil {
		fmt.Println("readFile: ", err2.Error())
		return
	}
	// num2 := strconv.Itoa(len(secondPer))
	thirdlyPer, err3 := ReadFile(userFile3)
	if err3 != nil {
		fmt.Println("readFile: ", err3.Error())
		return
	}
	// num3 := strconv.Itoa(len(thirdlyPer))
	check := false

	for _, v := range firstPer {
		md, _ := v.(map[string]interface{})
		if md["id"] == idPer {
			check = true
			break
		}
	}
	for _, v := range secondPer {
		md, _ := v.(map[string]interface{})
		if md["id"] == idPer {
			check = true
			break
		}
	}
	for _, v := range thirdlyPer {
		md, _ := v.(map[string]interface{})
		if md["id"] == idPer {
			check = true
			break
		}
	}

	fmt.Println(check)

	this.Data["json"] = map[string]interface{}{
		"success": true,
		"message": "success",
		"check":   check}
	// pkgname := this.GetString("a")
	this.ServeJSON()
	return
}
